Clover coverage report - Enterprise Web Services - 1.0
Coverage timestamp: Mon May 30 2005 17:10:32 CEST
file stats: LOC: 223   Methods: 3
NCLOC: 161   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ContextValidator.java 60.9% 83.3% 100% 77.1%
coverage coverage
 1   
 /*
 2   
  * Copyright 2001-2004 The Apache Software Foundation.
 3   
  * 
 4   
  * Licensed under the Apache License, Version 2.0 (the "License");
 5   
  * you may not use this file except in compliance with the License.
 6   
  * You may obtain a copy of the License at
 7   
  * 
 8   
  *      http://www.apache.org/licenses/LICENSE-2.0
 9   
  * 
 10   
  * Unless required by applicable law or agreed to in writing, software
 11   
  * distributed under the License is distributed on an "AS IS" BASIS,
 12   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13   
  * See the License for the specific language governing permissions and
 14   
  * limitations under the License.
 15   
  */
 16   
 
 17   
 package org.apache.geronimo.ews.ws4j2ee.context;
 18   
 
 19   
 import org.apache.axis.wsdl.fromJava.Emitter;
 20   
 import org.apache.axis.wsdl.symbolTable.BindingEntry;
 21   
 import org.apache.axis.wsdl.symbolTable.Parameter;
 22   
 import org.apache.axis.wsdl.symbolTable.Parameters;
 23   
 import org.apache.axis.wsdl.symbolTable.PortEntry;
 24   
 import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
 25   
 import org.apache.axis.wsdl.symbolTable.ServiceEntry;
 26   
 import org.apache.geronimo.ews.ws4j2ee.context.impl.EJBDDContextImpl;
 27   
 import org.apache.geronimo.ews.ws4j2ee.context.impl.SEIOperationImpl;
 28   
 import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.EJBContext;
 29   
 import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFPortComponent;
 30   
 import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFWebserviceDescription;
 31   
 import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
 32   
 import org.apache.geronimo.ews.ws4j2ee.toWs.UnrecoverableGenerationFault;
 33   
 
 34   
 import javax.wsdl.Fault;
 35   
 import javax.wsdl.Operation;
 36   
 import javax.wsdl.Port;
 37   
 import javax.wsdl.Service;
 38   
 import javax.xml.namespace.QName;
 39   
 import java.util.Collection;
 40   
 import java.util.Iterator;
 41   
 import java.util.List;
 42   
 import java.util.Map;
 43   
 
 44   
 /**
 45   
  * <p>Before the code genaration this class is used to analyis the parse inforemation
 46   
  * and make sure that the data populated in the different *Context* are
 47   
  * consistent. This class will populate the most of the infomation in the
 48   
  * MiscInfo.</p>
 49   
  *
 50   
  * @author Srinath Perera(hemapani@opensource.lk)
 51   
  */
 52   
 public class ContextValidator {
 53   
     private J2EEWebServiceContext context;
 54   
 
 55  26
     public ContextValidator(J2EEWebServiceContext context) throws GenerationFault {
 56  26
         try {
 57  26
             this.context = context;
 58   
         } catch (Exception e) {
 59  0
             e.printStackTrace();
 60  0
             throw GenerationFault.createGenerationFault(e);
 61   
         }
 62   
     }
 63   
 
 64   
     /**
 65   
      * <p>Just as in the server side this code find the WSDL Service and WSDLport and
 66   
      * populate them in the MiscInfo</p>
 67   
      *
 68   
      * @param emitter
 69   
      * @throws GenerationFault
 70   
      */
 71  11
     public void validateWithOutWSDL(Emitter emitter) throws GenerationFault {
 72  11
         try {
 73  11
             Collection servicesCollection = context.getWSDLContext().getServices();
 74  11
             if (servicesCollection.size() > 1)
 75  0
                 throw new UnrecoverableGenerationFault("we are supporting one service yet");
 76  11
             Iterator services = servicesCollection.iterator();
 77  11
             Service service = null;
 78  11
             if (services.hasNext()) {
 79  11
                 service = ((Service) services.next());
 80  11
                 context.getWSDLContext().settargetService(new ServiceEntry(service));
 81   
             }
 82   
             
 83   
             //get the service ports 
 84  11
             Collection portCollecton = service.getPorts().values();
 85   
             //just as before if there are more than one servie just let
 86   
             //it failed
 87  11
             if (servicesCollection.size() > 1)
 88  0
                 throw new UnrecoverableGenerationFault("we are supporting one port yet");
 89  11
             Iterator portList = portCollecton.iterator();
 90  11
             Port wsdlport = null;
 91  11
             while (portList.hasNext()) {
 92  11
                 wsdlport = (Port) portList.next();
 93  11
                 context.getWSDLContext().setTargetPort(wsdlport);
 94   
             }
 95  11
             if (wsdlport == null)
 96  0
                 throw new UnrecoverableGenerationFault("no port discription not match with the wsdl file");
 97  11
             QName bindingName = wsdlport.getBinding().getQName();
 98  11
             BindingEntry wsdlbinding = context.getWSDLContext().getBinding(bindingName);
 99  11
             context.getWSDLContext().settargetBinding(wsdlbinding);
 100  11
             QName portTypename = wsdlbinding.getBinding().getPortType().getQName();
 101  11
             PortTypeEntry port = context.getWSDLContext().getPortType(portTypename);
 102  11
             if (port == null)
 103  0
                 throw new UnrecoverableGenerationFault("port type must exits");
 104  11
             context.getWSDLContext().setTargetPortType(port);
 105   
         } catch (Exception e) {
 106  0
             e.printStackTrace();
 107  0
             throw GenerationFault.createGenerationFault(e);
 108   
         }
 109   
     }
 110   
 
 111  11
     public void validateWithWSDL() {
 112  11
         WSCFWebserviceDescription wscfwsdis = context.getWSCFContext().getWscfdWsDesxription();
 113  11
         WSCFPortComponent[] ports = wscfwsdis.getPortComponent();
 114  11
         if (ports == null || ports.length == 0)
 115  0
             throw new UnrecoverableGenerationFault("no port discription found in the" +
 116   
                     "webservices.xml file");
 117  11
         WSCFPortComponent port = ports[0];
 118  11
         context.getWSCFContext().setWscfport(port);
 119  11
         String ejbLink = port.getServiceImplBean().getEjblink();
 120   
         // context.getMiscInfo().setJaxrpcSEI(port.getServiceEndpointInterface());
 121  11
         if (ejbLink != null) {
 122  8
             String bean = port.getServiceEndpointInterface() + "Bean";
 123  8
             String home = port.getServiceEndpointInterface() + "Home";
 124  8
             String remote = port.getServiceEndpointInterface() + "EJB";
 125  8
             String local = port.getServiceEndpointInterface() + "LocalEJB";
 126  8
             String localHome = port.getServiceEndpointInterface() + "LocalHome";
 127  8
             EJBContext ejbcontext = context.getEJBDDContext();
 128  8
             if (ejbcontext == null) {
 129  0
                 ejbcontext = new EJBDDContextImpl(ejbLink, bean, home, remote, localHome, local);
 130   
             }
 131   
 //TODO remove this if not needed
 132  8
             if (ejbcontext.getImplBean() == null)
 133  0
                 ejbcontext.setImplBean(bean);
 134  8
             if (ejbcontext.getEjbhomeInterface() == null)
 135  0
                 ejbcontext.setEjbhomeInterface(home);
 136  8
             if (ejbcontext.getEjbRemoteInterface() == null)
 137  0
                 ejbcontext.setEjbRemoteInterface(remote);
 138  8
             if (ejbcontext.getEjbLocalHomeInterfce() == null)
 139  8
                 ejbcontext.setEjbLocalHomeInterfce(localHome);
 140  8
             if (ejbcontext.getEjbLocalInterface() == null)
 141  8
                 ejbcontext.setEjbLocalHomeInterfce(local);
 142  8
             context.getMiscInfo().setJ2eeComponetLink(port.getServiceImplBean().getEjblink());
 143   
         } else {
 144  3
             context.getMiscInfo().setImplwithEJB(false);
 145   
         }
 146  11
         QName portName = new QName(port.getWsdlPort().getNamespaceURI(), port.getWsdlPort().getLocalpart());
 147  11
         PortEntry wsdlport = context.getWSDLContext().getPort(portName);
 148  11
         if (wsdlport == null)
 149  0
             throw new UnrecoverableGenerationFault("wsdl port can not be null, you may have the " +
 150   
                     "wsdlport define wrongly on the webservices.xml");
 151  11
         Iterator services = context.getWSDLContext().getServices().iterator();
 152  11
         while (services.hasNext()) {
 153  11
             ServiceEntry service = (ServiceEntry) services.next();
 154  11
             Iterator portList = service.getService().getPorts().values().iterator();
 155  11
             while (portList.hasNext()) {
 156  11
                 if (((Port) portList.next()) == wsdlport.getPort()) {
 157  11
                     context.getWSDLContext().settargetService(service);
 158  11
                     break;
 159   
                 }
 160   
             }
 161   
         }
 162  11
         if (wsdlport == null)
 163  0
             throw new UnrecoverableGenerationFault("no port discription not match with the wsdl file");
 164  11
         QName bindingName = wsdlport.getPort().getBinding().getQName();
 165  11
         BindingEntry wsdlbinding = context.getWSDLContext().getBinding(bindingName);
 166  11
         context.getWSDLContext().settargetBinding(wsdlbinding);
 167  11
         QName portTypename = wsdlbinding.getBinding().getPortType().getQName();
 168  11
         context.getWSDLContext().setTargetPortType(context.getWSDLContext().getPortType(portTypename));
 169  11
         context.validate();
 170   
             
 171   
         //find and populate the information about the SEI in the 
 172   
         //MiscInfo
 173  11
         String seiName = context.getJAXRPCMappingContext()
 174   
                 .getServiceEndpointInterfaceName(context.getWSDLContext().getTargetPortType(), context.getWSDLContext().gettargetBinding());
 175  11
         context.getMiscInfo().setJaxrpcSEI(seiName);
 176  11
         List operations = context.getWSDLContext().getTargetPortType().getPortType().getOperations();
 177  11
         for (int i = 0; i < operations.size(); i++) {
 178  40
             SEIOperation seiOp = new SEIOperationImpl();
 179  40
             Operation op = (Operation) operations.get(i);
 180  40
             BindingEntry binding = context.getWSDLContext().gettargetBinding();
 181   
             
 182   
             //got to get the same parameter order as the JAXRPC mapper does
 183   
             //So I am using the same methods. Can somebody find something better?? 
 184  40
             Parameters parms = binding.getParameters(op);
 185   
             //set return type    
 186  40
             String returnType = context.getJAXRPCMappingContext().getJavaMethodReturnType(binding, op);
 187  40
             seiOp.setReturnType(returnType);
 188   
 
 189   
 
 190   
             //set method name 
 191  40
             String methodName = context.getJAXRPCMappingContext().getJavaMethodName(binding, op);
 192  40
             seiOp.setMethodName(methodName);
 193   
 
 194   
             //Iterator paramlist = parms.list.iterator();
 195  40
             String parameterName = null;
 196  40
             String parameterType = null;      
 197   
             
 198   
             //find the parameters and add each parameter to parameter list 
 199  40
             for (int paramCount = 0; paramCount < parms.list.size(); paramCount++) {
 200  54
                 Parameter p = (Parameter) parms.list.get(paramCount);
 201  54
                 parameterName = p.getName();
 202  54
                 parameterType = context.getJAXRPCMappingContext().getJavaMethodParamType(binding, op, paramCount, p.getType().getQName());
 203  54
                 seiOp.addParameter(parameterType, parameterName);
 204   
             }
 205   
             //let us find the faults
 206  40
             Map faults = parms.faults;
 207  40
             if (faults != null) {
 208  40
                 Iterator it = faults.values().iterator();
 209  40
                 while (it.hasNext()) {
 210  0
                     Fault fault = (Fault) it.next();
 211  0
                     String faulltName = context.getJAXRPCMappingContext()
 212   
                             .getExceptionType(fault.getMessage().getQName());
 213  0
                     seiOp.addFault(faulltName);
 214   
                 }
 215   
             }
 216  40
             context.getMiscInfo().setSEIOperations(seiOp);
 217   
         }
 218   
 //        
 219   
 //        String serviceName = context.getJAXRPCMappingContext()
 220   
 //                .getServiceInterfaceName(context.getMiscInfo().gettargetService());
 221   
     }
 222   
 }
 223